package it.koutifaris.travianmap.view.mainview;

import it.koutifaris.travianmap.R;
import it.koutifaris.travianmap.command.CommandOnMenuItemClickListener;
import it.koutifaris.travianmap.context.HasApplicationContex;
import it.koutifaris.travianmap.view.commandlistview.ListViewOnItemClickListener;
import android.view.Menu;
import android.widget.ListView;

public class MapListViewController extends HasApplicationContex {

	private final MapListView view;

	public MapListViewController() {
		view = new MainListViewImpl();
	}

	public void show() {
		getActivity().setContentView(R.layout.maplist);
		configure();
	}

	public void prepareMenu(Menu menu) {
		view.setOpenServerMenuItemClickHandler(
				menu,
				new CommandOnMenuItemClickListener(new OpenServersViewCommand()));
	}

	public void updateServerItem(String serverId, ServerItemView itemView) {

	}

	private void configure() {
		getListView().setAdapter(new MainListAdapter(getTravianMapContext(), view));
		getListView().setOnItemClickListener(new ListViewOnItemClickListener());
	}

	private ListView getListView() {
		return view.getListView();
	}
}
